﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Mysoft.MyCM.Web.Controllers
{
	/// <summary>
	/// Ajax控制器基类
	/// 包含用户校验，不包含选择客户校验
	/// </summary>
	[MAuthorizationFilter(MRequestType.Ajax, MValidateType.Ignor)]
	[MHandleExceptionFilter(MRequestType.Ajax)]
	public abstract class MAjaxBaseController : MBaseController
	{
		protected override void HandleUnknownAction(string actionName)
		{
			throw new M.MException("这个服务好像木有提供呢，确认您的请求是对的么？", M.MExceptionLevel.Stop);
		}

		/// <summary>
		/// 获取返回的JsonResult
		/// </summary>
		/// <param name="result">处理是否正确</param>
		/// <param name="userData">正确则包含用户对象，错误则应传入错误信息</param>
		/// <returns></returns>
		protected JsonResult GetJsonResult(bool result, object userData)
		{
			return GetJsonResult(new M.Web.AjaxHttpResult { Result = result, UserData = userData });
		}
		/// <summary>
		/// 获取返回的JsonResult
		/// </summary>
		/// <param name="httpResult">AjaxHttpResult对象</param>
		/// <returns></returns>
		protected JsonResult GetJsonResult(M.Web.AjaxHttpResult httpResult)
		{
			return new JsonResult
			{
				Data = httpResult
			};
		}
	}
}